//
//  NotificationViewController.m
//  ObjectCProject
//
//  Created by lvfeijun on 2022/12/8.
//

#import "NotificationViewController.h"
#import "WWNotificationCenter.h"

@interface NotificationViewController ()

@end

@implementation NotificationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(postNotification:) name:@"postNotification" object:nil];
    [[WWNotificationCenter defaultCenter] addObserver:self selector:@selector(postNotification:) name:@"postNotification" object:nil];
    
    [[NSNotificationCenter defaultCenter] addObserverForName:@"WWNotificationCenter" object:self queue:[NSOperationQueue currentQueue] usingBlock:^(NSNotification * _Nonnull note) {
        NSLog(@"NSNotificationCenter");
    }];
    [[WWNotificationCenter defaultCenter] addObserverForName:@"WWNotificationCenter" object:self queue:[NSOperationQueue currentQueue] usingBlock:^(WWNotification * _Nonnull note) {
        NSLog(@"WWNotificationCenter");
    }];
    
//    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//        [[NSNotificationCenter defaultCenter] postNotification:nil];
//    });
//
//    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//        [[WWNotificationCenter defaultCenter] postNotification:nil];
//    });
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [[NSNotificationCenter defaultCenter] postNotificationName:@"postNotification" object:self userInfo:nil];
    });
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(7 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [[WWNotificationCenter defaultCenter] postNotificationName:@"WWNotificationCenter" object:self userInfo:nil];
    });
}

-(void)postNotification:(NSNotification *)notification
{
    NSLog(@"%@", notification.name);
    NSLog(@"发送通知    ");
}

- (void)dealloc
{
//    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"" object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [[WWNotificationCenter defaultCenter] removeObserver:self];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
